<?php
/**
 * User: aka
 * Date: 2018/6/27
 * Time: 17:09
 */

namespace app\reception\controller;


class Home extends Front
{
    static private $phone = 'enterprise_phone';
    static private $enterpriseInfo = 'enterprise_info';
    static private $enterpriseAdd = 'enterprise_address';
    static private $sowingImg = 'sowing_img';
    static private $classificationInfo = 'classification_info';
    static private $foodInfo = 'food_info';

    private function classificationData(int $pidNum) : array
    {
        $classification = db(self::$classificationInfo)->where(['pid'=>$pidNum,'status'=>1])->select();
        return $classification;
    }

    private function groupFoodTopData(array $where,string $group) : array
    {
        $foodTopdata = db(self::$foodInfo)->where($where)->page($group)->select();
        return $foodTopdata;
    }

    public function indexView()
    {
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $sowingImgData = db(self::$sowingImg)->where(['status'=>1])->select();
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        $computer = $this->classificationData(1);
        $printing = $this->classificationData(4);
        $hall = $this->classificationData(5);
        $office = $this->classificationData(6);

        $computerTop1 = $this->groupFoodTopData(['top'=>1,'status'=>1],'1,2');
        $computerTop2 = $this->groupFoodTopData(['top'=>1,'status'=>1],'2,2');
        $computerTop3 = $this->groupFoodTopData(['top'=>1,'status'=>1],'3,2');
        $printingTop1 = $this->groupFoodTopData(['top'=>4,'status'=>1],'1,2');
        $printingTop2 = $this->groupFoodTopData(['top'=>4,'status'=>1],'2,2');
        $printingTop3 = $this->groupFoodTopData(['top'=>4,'status'=>1],'3,2');
        $hallTop1 = $this->groupFoodTopData(['top'=>5,'status'=>1],'1,2');
        $hallTop2 = $this->groupFoodTopData(['top'=>5,'status'=>1],'2,2');
        $hallTop3 = $this->groupFoodTopData(['top'=>5,'status'=>1],'3,2');
        $officeTop1 = $this->groupFoodTopData(['top'=>6,'status'=>1],'1,2');
        $officeTop2 = $this->groupFoodTopData(['top'=>6,'status'=>1],'2,2');
        $officeTop3 = $this->groupFoodTopData(['top'=>6,'status'=>1],'3,2');
        $assignData = [
            'phone'=>$phone,
            'address'=>$enterpriseAdd,
            'ercode'=>$enterpriseInfoData['ercode'],
            'sowimg'=>$sowingImgData,
            'computer'=>$computer,
            'printing'=>$printing,
            'hall'=>$hall,
            'office'=>$office,
            'computerTop1'=>$computerTop1,
            'computerTop2'=>$computerTop2,
            'computerTop3'=>$computerTop3,
            'printingTop1'=>$printingTop1,
            'printingTop2'=>$printingTop2,
            'printingTop3'=>$printingTop3,
            'hallTop1'=>$hallTop1,
            'hallTop2'=>$hallTop2,
            'hallTop3'=>$hallTop3,
            'officeTop1'=>$officeTop1,
            'officeTop2'=>$officeTop2,
            'officeTop3'=>$officeTop3,
        ];
        return view('index',$assignData);
    }

    private function getEnterpriseInfoData()
    {
        return $this->getDbOperation()->find(self::$enterpriseInfo,['id'=>1]);
    }

    public function recoveryView()
    {
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        return view('recovery',['recovery'=>$enterpriseInfoData['enterprise_recovery'],'phone'=>$phone,'address'=>$enterpriseAdd,'ercode'=>$enterpriseInfoData['ercode']]);
    }

    public function cooperationView()
    {
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        return view('cooperation',['cooperation'=>$enterpriseInfoData['enterprise_cooperation'],'phone'=>$phone,'address'=>$enterpriseAdd,'ercode'=>$enterpriseInfoData['ercode']]);
    }

    public function aboutUsView()
    {
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        return view('aboutUs',['aboutUs'=>$enterpriseInfoData['about_us'],'phone'=>$phone,'address'=>$enterpriseAdd,'ercode'=>$enterpriseInfoData['ercode']]);
    }

    public function processFlowView()
    {
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        return view('processFlow',['processFlow'=>$enterpriseInfoData['process_flow'],'phone'=>$phone,'address'=>$enterpriseAdd,'ercode'=>$enterpriseInfoData['ercode']]);
    }

    public function mattersNeedingAttentionView()
    {
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        return view('mattersNeedingAttention',['mattersNeedingAttention'=>$enterpriseInfoData['matters_needing_attention'],'phone'=>$phone,'address'=>$enterpriseAdd,'ercode'=>$enterpriseInfoData['ercode']]);
    }

    public function exemptionFromDepositView()
    {
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        return view('exemptionFromDeposit',['exemptionFromDeposit'=>$enterpriseInfoData['exemption_from_deposit'],'phone'=>$phone,'address'=>$enterpriseAdd,'ercode'=>$enterpriseInfoData['ercode']]);
    }

    public function allFoodView()
    {
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        $computer = $this->classificationData(1);
        $printing = $this->classificationData(4);
        $hall = $this->classificationData(5);
        $office = $this->classificationData(6);
//        $pageData = db(self::$foodInfo)->where('status','eq',1)->where('food_classification','neq','1')->where('food_classification','neq','4')->where('food_classification','neq','5')->where('food_classification','neq','6')->paginate(12);
        $pageData = db(self::$foodInfo)->where('status','eq',1)->paginate(12);
        $assignData = [
            'phone'=>$phone,
            'address'=>$enterpriseAdd,
            'ercode'=>$enterpriseInfoData['ercode'],
            'computer'=>$computer,
            'printing'=>$printing,
            'hall'=>$hall,
            'office'=>$office,
            'pageData'=>$pageData
        ];
        return view('allFood',$assignData);
    }

    public function typeFoodView()
    {
        $getParamId = input('param.id');
        $id = base64_decode($getParamId);
        $classificationName = $this->getDbOperation()->find(self::$classificationInfo,['id'=>$id]);
        $phone = $this->getDbOperation()->find(self::$phone,['id'=>1]);
        $enterpriseInfoData = $this->getEnterpriseInfoData();
        $enterpriseAdd = $this->getDbOperation()->find(self::$enterpriseAdd,['id'=>1]);
        $computer = $this->classificationData(1);
        $printing = $this->classificationData(4);
        $hall = $this->classificationData(5);
        $office = $this->classificationData(6);
        $pageData = $this->getDbOperation()->wherePaginate(self::$foodInfo,['food_classification'=>$id,'status'=>1],12);
        $assignData = [
            'phone'=>$phone,
            'address'=>$enterpriseAdd,
            'ercode'=>$enterpriseInfoData['ercode'],
            'computer'=>$computer,
            'printing'=>$printing,
            'hall'=>$hall,
            'office'=>$office,
            'pageData'=>$pageData,
            'type'=>$classificationName['classification_name']
        ];
        return view('typeFood',$assignData);
    }
}